<?php
$cartoon = $this->ret['cartoon'];
?>
<link rel="stylesheet" href="/res/editor/css/editor.css" type="text/css">
<script  type="text/javascript" src="/res/editor/js/webeditor.js"></script>
<script src="/res/cartoon/js/cartoon.js" tppe="text/javascript"></script>
<h2>我的漫画->添加漫画</h2>
<P></P>
<form id="form1" action="<?=self::_makeURL('cartoon','index','add_form'==$this->action?'add':'edit')?>"   method="post" enctype="multipart/form-data">
<table class="raceTable" border="1" align="left" cellspacing="8" cellpadding="5" style="width: 800px; border: 2px solid rgb(204, 204, 204);">
	<tr>
		<td>漫画名称：</td> 
		<td>
		<input  class="input_text" type="text" title="漫画名称"  id="cartoon_name" name="cartoon_name" value="<?=$cartoon['ct_title']?>" />
		<input type="hidden" name="id" value="<?=$cartoon['id']?>" />
		</td>
	</tr>
	<tr>
		<td>漫画别名:</td>
		<td><input class="input_text" type="text" title="漫画别名" id="alias_name" name="alias_name" value="<?=$cartoon['ct_alias_name']?>" /></td>
	</tr>
	<tr>
		<td>漫画原名:</td>
		<td><input class="input_text" type="text" title="漫画原名" id="real_name" name="real_name" value="<?=$cartoon['ct_real_name']?>" /></td>
	</tr>
	<tr>
	<td>漫画分类：</td>
	<td>
	<div>
       <span style="float:left">
       	<?if($this->ret['catelist']):?>
           <select class="m_select" multiple="multiple" id="msel_cate1">
           <?foreach ($this->ret['catelist'] AS $cate):?>
           <option value="<?=$cate['id']?>"><?=$cate['cate_name']?></option>
           <?endforeach;?>
           </select>
       </span>
       <span style="float:left;margin:20px">
            <input type="button" style="width:50px" class="btn_submit" value="&gt;&gt;添加" onclick="MoveOption('msel_cate1','msel_cate2',true)"><br>
          <input type="button" style="width:50px" class="btn_submit" value="&lt;&lt;取消" onclick="MoveOption('msel_author1','msel_cate2',false);">
       </span>
       <span style="float:left">
           <select class="m_select" multiple="multiple" id="msel_cate2">
             <?if($cartoon['ct_category']):?>
             <?php $catelist = explode(',',$cartoon['ct_category']); ?>
             <?foreach( $catelist as $v):?>
             	<option value="<?=$v?>" ><?=$this->ret['catelist'][$v]['cate_name']?></option>
             <?endforeach;?>
             <?endif;?>  
           </select>
         <?endif;?>
        </span>
      </div>
      <input type="hidden" id="selected_cate" name="selected_cate">
      <input type="hidden" id="selected_cate_name" name="selected_cate_name">
      
	</td>
	</tr>
	<tr>
	<td>漫画作者</td>
	<td>
	<div>
       <span style="float:left">
       	<?if($this->ret['authors']):?>
           <select class="m_select" multiple="multiple" id="msel_author1">
           <?foreach ($this->ret['authors'] AS $au):?>
           <option value="<?=$au['name']?>"><?=$au['name']?></option>
           <?endforeach;?>
           </select>
       </span>
       <span style="float:left;margin:20px">
            <input type="button" style="width:50px" class="btn_submit" value="&gt;&gt;添加" onclick="MoveOption('msel_author1','msel_author2',true)"><br>
          <input type="button" style="width:50px" class="btn_submit" value="&lt;&lt;取消" onclick="MoveOption('msel_author1','msel_author2',false);">
       </span>
       <span style="float:left">
           <select class="m_select" multiple="multiple" id="msel_author2">
             <?if($cartoon['ct_author']):?>
             <?php $series = explode(',',$cartoon['ct_author']);             ?>
             <?foreach( $series as $v):?>
             	<option value="<?=$v?>" ><?=$v?></option>
             <?endforeach;?>
             <?endif;?>  
           </select>
         <?endif;?>
        </span>
      </div>
      <input type="hidden" id="selected_author" name="selected_author">
      <input type="hidden" id="selected_author_name" name="selected_author_name">
	</td>
	</tr>
	
	<!--<td>所属系列：</td>
	<td>
	<div>
       <span style="float:left">
        <?if($this->ret['tags'][3]):?>
           <select class="m_select" multiple="multiple" id="seselect1">
           <?foreach ($this->ret['tags'][3] AS $series):?>
            <option value="<?=$series['tag_name']?>"><?=$series['tag_name']?></option>
           <?endforeach;?>
          </select>
       </span>
       <span style="float:left;margin:20px">
            <input type="button" style="width:50px" class="btn_submit" value="&gt;&gt;添加" onclick="MoveOption('seselect1','seselect2',true)"><br>
          <input type="button" style="width:50px" class="btn_submit" value="&lt;&lt;取消" onclick="MoveOption('seselect1','seselect2',false);">
       </span>
       <span style="float:left">
           <select class="m_select" multiple="multiple" id="seselect2">
             <?if($cartoon['ct_series']):?>
             <?php $series = explode(',',$cartoon['ct_series'])?>
             <?foreach( $series as $v):?>
             	<option value="<?=$v?>"><?=$v?></option>
             <?endforeach;?>
             <?endif;?>
           </select>
           <?endif;?>
        </span>
      </div>
      <input type="hidden" id="selected_series"  name="selected_series" />
     </td>
	</tr>-->
	<tr>
	<td>标签：</td>
	<td><input title="标签" type="text" class="input_text" name="tags" value="<?=$cartoon['ct_tags']?>" /></td>
	</tr>
	<tr>
	<td>漫画拼音：</td>
	<td><input class="input_text" type="text" title="漫画拼音" name="cartoon_py" value="<?=$cartoon['ct_py']?>" /></td>
	</tr>
	<tr>
	<td>漫画地域：</td>
	<td>
	<input type="radio" name="zone" value="1" <?= (1==$cartoon['ct_nation'])?'checked="checked"':''?>>日本
	<input type="radio" name="zone" value="2" <?= (2==$cartoon['ct_nation'])?'checked="checked"':''?>>欧美
	<input type="radio" name="zone" value="3" <?= (3==$cartoon['ct_nation'])?'checked="checked"':''?>>港台
	<input type="radio" name="zone" value="4" <?= (4==$cartoon['ct_nation'])?'checked="checked"':''?>>内地
	</td>
	</tr>
	<tr>
	<td>读者群：</td>
	<td><input type="radio" name="readerGroup" value="1" <?= (1==$cartoon['ct_reader_group'])?'checked="checked"':''?> >儿童漫画&nbsp;&nbsp;&nbsp;
	<input type="radio" name="readerGroup" value="2" <?= (2==$cartoon['ct_reader_group'])?'checked="checked"':''?> >少年漫画&nbsp;&nbsp;&nbsp;
	<input type="radio" name="readerGroup" value="3" <?= (3==$cartoon['ct_reader_group'])?'checked="checked"':''?>>少女漫画&nbsp;&nbsp;&nbsp;
	</td>
	</tr>
	<tr>
	<td>语言：</td>
	<td><input type="radio" value="ch" name="language" <?= ("ch" ==$cartoon['ct_lang'])?'checked="checked"':''?> >中文
	<input type="radio" value="jp" name="language" <?= ("jp"==$cartoon['ct_lang'])?'checked="checked"':''?> >日文
	<input type="radio" value="en" name="language" <?= ("en"==$cartoon['ct_lang'])?'checked="checked"':''?> >英文</td>
	</tr>
	<tr>
	<td>漫画状态：</td>
	<td><input type="radio" value="1" name="status" <?= (1==$cartoon['ct_flag'])?'checked="checked"':''?> >连载中
	<input type="radio" value="2" name="status" <?= (2==$cartoon['ct_flag'])?'checked="checked"':''?>>已完结</td>
	</tr>
	<tr>
	<td>漫画封面：</td>
	<td><input type="file" name="cover" ><?if($actinfo['act_logo']):?><img src="<?=$cartoon['ct_cover']?>" width="130" height="130" /><?endif;?></td>
	</tr>
	<tr>
	<td>简单介绍：</td>
	<td>
	<input type="hidden" id="s_desc" name="s_desc" />
	<div id="postcontent">
		<textarea id="simple_desc" name="simple_desc" ><?=$cartoon['ct_simple_desc']?></textarea>
	</div>
	<script type="text/javascript">
	var e_fontsize = true;
	var e_face = true;
	var e_media = false;
	var e_bold = true;
	var e_InsertOrderedList = true;
	var e_italic = true;
	var e_underline = true;
	var e_JustifyLeft = true;
	var e_JustifyCenter = true;
	var e_JustifyRight = true;
	var e_font = true;
	var e_color = true;
	var e_backcolor = false;
	var e_img = true;
	var e_link = true;
	var e_uploadimg = false;
	var e_piclink = false;
	var e_CommentFace = false;
	var e_face = false;
	var e_toolbarbg = true;
	s_content_editor = new webEditor("s_content_editor" , 	$("postcontent"),500,200);
	s_content_editor.init($('simple_desc').value);
</script>
	</td>
	</tr>
	<tr>
	<td>详细介绍：</td>
	<td><input type="hidden" id="_cartoon_desc" name="_cartoon_desc" />
	<div id="reward_postcontent">
		<textarea id="cartoon_desc" name="cartoon_desc" ><?=$cartoon['ct_desc']?></textarea>
	</div>
	<script type="text/javascript">
	var e_fontsize = true;
	var e_face = false;
	var e_media = true;
	var e_bold = true;
	var e_InsertOrderedList = true;
	var e_italic = true;
	var e_underline = true;
	var e_JustifyLeft = true;
	var e_JustifyCenter = true;
	var e_JustifyRight = true;
	var e_font = true;
	var e_color = true;
	var e_backcolor = false;
	var e_img = true;
	var e_link = true;
	var e_uploadimg = false;
	var e_piclink = false;
	var e_CommentFace = false;
	var e_face = false;
	var e_toolbarbg = true;
	content_editor = new webEditor(	"content_editor" , 	$("reward_postcontent")  ,675,350);
	content_editor.init($('cartoon_desc').value);
	</script>
	</td>
	</tr>
	<tr >
	<td colspan="2" align="center" style="heigth:30px">
	<input type="button" name="submit_btn"  onclick="javascript:return Cartoon.checkSubmit('form1');"  value="<?php if('edit_form'== $this->action) echo '修改'; else echo '添加';?>"  /> <input type="reset" value="取消"/></td>
</tr>
</table>
</form>
<script language="javascript">
function MoveOption(from,to,pos)
{
    var _from=document.getElementById(from);
    var	_to=document.getElementById(to);
    var Array=[];
    if(pos){
        if(_from.options.length<=0){
               return;
    	}
    	if(_from.selectedIndex<0){
         	return;
   	 	}
    	for(var i=0;i<_from.options.length;i++){
      		if(_from.options[i].selected){
          	Array.push(_from.options[i].cloneNode(true));
       	}
    	}
    	for(var i=0;i<Array.length;i++){
       		var len = _to.options.length;
       		var add = true;
       		for(var j=0;j<len;j++){
	          	if (Array[i].value == _to.options[j].value){
               		add =false;
               		break;
          		}
       		}
       		if (add){
          	_to.appendChild(Array[i]);
       		}
     	}
     }else{
        if(_to.options.length<=0){
            return;
        }
        if(_to.selectedIndex<0){
           return;
        }
        for(var i=0;i<_to.options.length;i++)
        {
            if(_to.options[i].selected){
               _to.removeChild(_to.options[i]);
            }
         }
      }     
}
/*function dealSelect(name,id,nid,checkvalue,val){
	var myoptions = $('#'+name).get(0).options;
    var len = myoptions.length;
    var select_type = '';
    var select_type_name = '';
    for (var i=0;i<len;i++){
        select_type += myoptions[i].value+',';
        select_type_name += myoptions[i].text+',';
    }
    
    if (select_type == ''){
        if(checkvalue){
	        alert('没有选中'+val);
	        return false;
        }else{
       	    $('#'+id).val('');
       	    return true;
        }
    }else{
        select_type = select_type.substring(0,select_type.length -1);
        select_type_name =select_type_name.substring(0,select_type_name.length -1);
        $('#'+id).val(select_type);
        $('#'+nid).val(select_type_name);

        return true;
    }
}

function testPY(str){
	var patrn=/^[0-9A-Za-z][0-9A-Za-z_-]*$/; 
    if (!patrn.exec(str)) return false 
    return true 
}

function checkInput(){
	
	if (!dealSelect('myselect1','selected_types','selected_types_name',true,'类型')){
		$('#myselect1').focus()
	    return false;
	}
	if (!dealSelect('seselect1','selected_series','selected_series_name',false,'系列')){
		$('#seselect1').focus()
        return false;
    }
	if (!dealSelect('auselect1','selected_authors','selected_authors_name',true,'作者')){
		$('#auselect1').focus()
        return false;
    }

	if ($.trim($('#comic_name').val()) == ''){
	    alert('请输入漫画名称。');
	    $('#comic_name').focus()
	    return false;
	}


	if (!testPY($('#comic_py').val())){
		alert('请输入正确的漫画拼音。');
        $('#comic_py').focus();
        return false;
	}
	
	var radioZone = $(':radio[name=zone][checked]').val();
	if(!radioZone || radioZone.length == 0){
		alert('请选择漫画的地域！');
		return false;
	}

	var langZone = $(':radio[name=language][checked]').val();
	if(!langZone || langZone.length == 0){
		alert('请选择漫画的语言！');
		return false;
	}

	var statusZone = $(':radio[name=status][checked]').val();
	if(!statusZone || statusZone.length == 0){
		alert('请选择漫画的状态！');
		return false;
	}

	readerGroup = getReaderGroup();
	if(!readerGroup){
		alert('请选择读者群！');
		return false;
	}
//	if ($.trim($('#first_letter').val()) == ''){
//        alert('请输入漫画首字母。');
//        $('#first_letter').focus();
//        return false;
//    }

//	if ($.trim($('#keywords').val()) == ''){
//        alert('请输入漫画关键字。');
//        $('#keywords').focus();
//        return false;
//    }
//
//	if ($.trim($('#comic_content').val()) == ''){
//        alert('请输入简单介绍。');
//        $('#comic_content').focus();
//        return false;
//    }

	if ($.trim($('#introduction').val()) == ''){
        alert('请输入详细介绍。');
        $('#introduction').focus();
        return false;
    }

	$('#comic_form').submit();
    
    return true;
}*/

function search_tag(type,id,content_id){
	var data = 'na='+$('#'+id).val()+'&t='+type;
	$.ajax({
		 type: "POST",
		 url: g_js_root+"tag/ajax",
		 data:  data,
		 success: function(content){
               $('#'+content_id).html(content);
		   } 
	}); 
}

function receiveImageUpload(img_url){
    $('#upload').val(img_url);
    return false;
}

function getReaderGroup(){
	var readerGroup = $(":input[name=readerGroup][checked]").val();
	if(!readerGroup || readerGroup.length ==0){
		return false;
	}
	return readerGroup;
}
</script>